# -*- coding: utf-8 -*-
"""
Created on Tue Dec  2 11:10:37 2020
pytest 226_unittestandpytest.py -v
@author: kanwa
"""

# import time
# import unittest
# from selenium import webdriver
# from selenium.webdriver.common.keys import Keys
#
# class PythonOrgSearch(unittest.TestCase):
#
#     def setUp(self):
#         self.driver = webdriver.Chrome('./diver/chromedriver')
#
#     def test_search_in_python_org(self):
#         driver = self.driver
#         driver.get("http://www.python.org")
#         self.driver.set_window_size(1290, 690)
#         elem = driver.find_element_by_name("q")
#         elem.send_keys("pycon")
#         elem.send_keys(Keys.RETURN)
#         time.sleep(1)
#
#     def tearDown(self):
#         self.driver.close()
#
# if __name__ == "__main__":
#     unittest.main()

# pytest
import pytest
import time
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


class Testdemo():
    def setup_method(self):
        self.driver = webdriver.Chrome('./diver/chromedriver')

    def teardown_method(self):
        print('tear down')
        self.driver.quit()

    def test_test1(self):
        self.driver.get("https://www.baidu.com/")
        self.driver.set_window_size(1290, 690)
        elem = self.driver.find_element_by_name("wd")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        time.sleep(1)

    def test_test2(self):
        self.driver.get("https://www.python.org/")
        self.driver.set_window_size(1290, 690)
        elem = self.driver.find_element_by_name("q")
        elem.send_keys("pycon")
        elem.send_keys(Keys.RETURN)
        time.sleep(1)

# # pytest
# import pytest
# import time
# from selenium import webdriver
# from selenium.webdriver.common.keys import Keys
# # driver = webdriver.Chrome()
# # @pytest.fixture(scope="function",autouse=True)
#
#
# @pytest.fixture(scope="class", autouse=True)
# def all_beginning(request):
#     """setup-teardown"""
#     driver = webdriver.Chrome('./diver/chromedriver')
#     # request.instance.driver = driver
#     request.cls.driver = driver
#     yield
#     print("执行teardown!")
#     driver.close()
#
# # @pytest.mark.usefixtures("all_beginning")
# class Testdemo:
#     def test_test1(self):
#         # all_beginning.get("https://www.python.org/")
#         self.driver.get("https://www.python.org/")
#         self.driver.set_window_size(1290, 690)
#         elem = self.driver.find_element_by_name("q")
#         elem.send_keys("pycon")
#         elem.send_keys(Keys.RETURN)
#         time.sleep(10)
#     def test_test2(self):
#         # all_beginning.get("https://www.python.org/")
#         self.driver.get("https://docs.pytest.org/")
#         self.driver.set_window_size(1290, 690)
#         time.sleep(10)
#

# import pytest
# from selenium import webdriver

# @pytest.fixture()
# def setup(request):
#     print("initiating chrome driver")
#     driver = webdriver.Chrome()
#     request.instance.driver = driver
#     driver.get("http://seleniumeasy.com/test")
#     driver.maximize_window()

#     yield driver
#     driver.close()

# @pytest.mark.usefixtures("setup")
# class TestExample:
#     def test_title(self):
#         print("Verify title...")
#         assert "Selenium Easy" in self.driver.title

#     def test_content_text(self):
#         print("Verify content on the page...")
#         centerText = self.driver.find_element_by_css_selector('.tab-content .text-center').text
#         assert "WELCOME TO SELENIUM EASY DEMO" == centerText
